package cn.kow.kmall.core.jpa;

import cn.kow.kmall.core.entity.BaseEntity;
import cn.kow.kmall.core.jpa.query.BasePageQuery;
import cn.kow.kmall.core.jpa.query.BaseQuery;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.NoRepositoryBean;

import java.util.List;

/**
 * @Author: lijun
 * @Description:
 * @Date: Created in 2020-04-13 10:01
 * @Modified By:
 */
@NoRepositoryBean
public interface BaseJpaRepository<T extends BaseEntity, ID> extends JpaRepository<T, ID>, JpaSpecificationExecutor<T> {

    /**
     * 根据ID获取对象,不存在返回null
     * @param   id
     * @return  T
     */
    T getById(ID id);

    /**
     * 更新对象
     * @param entity  对象
     * @return 结果
     */
    T update(T entity);

    /**
     * 创建对象
     * @param entity  对象
     * @return 结果
     */
    T create(T entity);

    void deleteAllById(Iterable<ID> ids);

    /**
     * 返回所有未删除的对象
     * @param record    对象
     * @return 结果
     */
    <S extends T> List<S> listAll(S record);

    <S extends T> List<S> listAll(S record, Sort sort);

    <S extends T> S getOne(S record);

    T queryOne(BaseQuery query);

    Page<T> queryByPage(BasePageQuery query);

    List<T> queryAll(BaseQuery query);


}
